Skip to content

Fix handshake deadlines and retry timing - #162

Merged
algesten merged 16 commits into
mainfrom
dev/161
Oct 17, 2026
Merged

algesten merged 16 commits into
mainfrom
dev/161

Conversation

@xnorpx

@xnorpx xnorpx commented Sep 5, 2026 •

Copy link
Copy Markdown
Collaborator

Start the handshake deadline at the first ClientHello and honor handshake_timeout, flight_start_rto, and flight_retries consistently across DTLS 1.2, DTLS 1.3, and Auto. Previously, idle time could consume the handshake budget, and Auto used its own retry schedule. Fixes #161.

handle_timeout(now) remains the sole clock driver. Clients start the deadline when the first ClientHello fragment is emitted; servers start when the first structurally valid ClientHello fragment is accepted. Construction and idle time consume no budget. The same absolute deadline survives Auto version selection, cookie exchanges, later flights, and retransmissions. A rejected ClientHello body does not reset this per-peer deadline.

A shared timer implements the deadline and flight retry policy:

  • Flight timers arm when output is emitted, so queued output and BufferTooSmall do not consume retry time or attempts.
  • Auto clients carry their outstanding ClientHello retry state into the selected protocol version.
  • Timed and duplicate-triggered resends share the configured retry budget. Zero retries disables ordinary retransmissions; responses to the peer's final-flight retransmissions remain available after local completion, as required by the RFCs.
  • Completion disables the handshake deadline. DTLS 1.3 KeyUpdate continues to use the configured flight retry policy.

Retry jitter is proportional ±25% of the RTO. Timing durations must be nonzero and at most 3650 days, and deadline/backoff arithmetic handles overflow. Defaults remain 40 seconds for the handshake, a 1-second initial RTO, and 4 retries. Documentation and the event-loop example show how to advance the clock and drain output.

Validation covers both crypto providers, 23 timing integration tests, formatting, Clippy, and rustdoc. Timing tests exercise idle peers, fragmented ClientHellos, Auto handoff, cookie exchanges, retry exhaustion, undersized output buffers, duplicate flights, and final-flight recovery.

Comment thread src/auto.rs Fixed
Comment thread src/dtls13/engine.rs Fixed
Comment thread tests/timing.rs Fixed
@xnorpx

xnorpx commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot fix snowflake ci and codeql

Copilot AI commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

@copilot fix snowflake ci and codeql

Fixed in e1d91cf, 2ef48c6, and 05185c8. Snowflake’s DTLS 1.2 import violation is corrected, and the CodeQL-sensitive debug/logging paths now avoid formatting potentially sensitive output while retaining safe diagnostics. Local validation passed: cargo fmt --all -- --check, cargo test --all-features --test timing, focused auto timing test, cargo clippy --workspace --all-targets --all-features -- -D warnings, and secret scanning.

Comment thread src/auto.rs Fixed
Comment thread src/dtls13/engine.rs Fixed
Comment thread src/dtls13/engine.rs Fixed
Comment thread src/dtls13/engine.rs Fixed
@xnorpx

xnorpx commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot we are still failing CodeQL CI check

Copilot AI commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

@copilot we are still failing CodeQL CI check

Fixed in fa00010 and 26b6fe8. The CodeQL-flagged sinks now avoid logging dynamic data entirely: DTLS 1.3 queue-full warnings are static, timing panic paths no longer format output fields, and the auto timing match remains exhaustive with static per-variant messages. Local validation passed: cargo fmt --all -- --check, focused auto timing test, cargo test --all-features --test timing, cargo clippy --workspace --all-targets --all-features -- -D warnings, and secret scanning. The final CodeQL validation reported 0 Rust alerts before the last diagnostic-only follow-up; the GitHub workflow created for 26b6fe8 is currently action_required with no jobs started.

xnorpx and others added 5 commits October 17, 2026 22:11
Keep the CHANGELOG entry within the 120-column limit and split the
DTLS 1.2 engine message imports onto single-line `use` statements.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CodeQL treats a tuple that directly holds `self.certificate` as sensitive
data and taints every element, so `ClientPending::into_parts` tainted the
config that the engines log in their queue-full warnings. Bind the fields
before building the tuple. Also stop formatting the BufferTooSmall size in
the timing test helper, which CodeQL tainted through `Output::PeerCert`.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@algesten algesten changed the title Start handshake clocks at ClientHello and honor timing settings consistently Fix handshake timing Oct 17, 2026
@algesten algesten changed the title Fix handshake timing Fix handshake deadlines and retry timing Oct 17, 2026
@algesten
algesten merged commit 867218d into main Oct 17, 2026
46 checks passed
@algesten
algesten deleted the dev/161 branch October 17, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Start handshake clocks at ClientHello and honor timing settings consistently

4 participants